<?php
class IndexController extends BaseSiteController
{
	public $layout = '//../modules/site_frontend/views/layouts/sidebar_right';
	
	public function actions()
	{
		return array(
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'minLength' => 4,
				'maxLength' => 4,
				'backColor'	=>	0x5B1509,
				'foreColor'	=>	0xFFFFFF,
				'width'		=> 70,
				'height'	=> 22,
				'offset'	=> 1,
				'padding'	=>	2,
				'testLimit'	=>	1,
				'fontFile'	=>	Yii::getPathOfAlias('ext').'/arial.ttf'
			),
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}
	public function actionIndex()
	{
		$this->render('index');
	}
	public function actionPagex()
	{
		$alias = Yii::app()->request->getParam('page_alias');
		$page = Pages::getPageByAlias($alias);
		$this->render('pagex', array('page'=>$page));
	}
	public function actionNews()
	{
		$alias = Yii::app()->request->getParam('alias');
		$Article = FNews::getArticleByAlias($alias);
		$Comment = new CommentForm;
		if(isset($_POST['CommentForm']))
		{
			$Comment->attributes=$_POST['CommentForm'];
			if($Comment->validate()){
				$model = new Comment;
				$model->attributes = $_POST['CommentForm'];
				$model->post_id = FNews::getIdByAlias($alias);
				$model->create_time = time();
				$model->modified = date('Y-m-d H:i:s');
				
				if($model->save())
				{
					Yii::app()->user->setFlash('commentsubmit', Yii::t('app', 'Thank for your comment.'));
				}
				$this->refresh(true,'#comment');
			}
			$Errors = $Comment->getErrors();
			if($Errors['author'])			
				Yii::app()->user->setFlash('author_error',$Errors['author'][0]);
			if($Errors['email'])			
				Yii::app()->user->setFlash('email_error',$Errors['email'][0]);
			if($Errors['content'])			
				Yii::app()->user->setFlash('content_error',$Errors['content'][0]);
			if($Errors['verifyCode'])			
				Yii::app()->user->setFlash('verifyCode_error',$Errors['verifyCode'][0]);
			echo '<script>window.location.hash = \'comment\'</script>';
		}
		if($Article==false)
			throw new CHttpException(301);
		$this->render('detail', array('Article'=>$Article, 'model'=>$Comment));
	}
	public function actionError()
	{
		$this->render('error');
	}
	/**
	 * Creates a new comment.
	 * This method attempts to create a new comment based on the user input.
	 * If the comment is successfully created, the browser will be redirected
	 * to show the created comment.
	 * @param Post the post that the new comment belongs to
	 * @return Comment the comment instance
	 */
}